;+
;PURPOSE
;	make a good looking histogram
;SYNTAX
;	rplothist, x[,_extra=_extra, /overplot, hist=hist, yhist=yhist $
; 	       xhist=xhist]
;INPUTS
;	x: the array to histogram
;	_extra: keywords to pass to plot
;	hist: keywords to pass to histogram
;		e.g. to set binsize=2 do
;		rplothist, x, hist={binsize:2}
;	/overplot
;	yhist: saves the y values of the histogram
;	xhist: save the x values of the histogram (the center points of 
;		the bins)
;
;Written by R. da Silva, UCSC, 3-16-2010
;-
pro rplothist, x, _extra=_extra, overplot=overplot, hist=hist, yhist=yhist, $
	xhist=xhist, norm=norm
h=histogram(x, loc=xloc, _extra=hist)
if keyword_set(norm) then h=h/total(h)
binss=xloc[1]-xloc[0]
locs=xloc+binss/2.
nh=n_elements(h)

if NOT keyword_set(overplot) then plot, locs, h, _extra=_extra, ps=10 else $
	oplot, locs, h, _extra=_extra, ps=10
for ifill=0, n_elements(xloc)-1 do begin
    oplot, [xloc[ifill],xloc[ifill]], [0, h[ifill]], _extra=_extra
    oplot, [xloc[ifill],xloc[ifill]]+binss, [0, h[ifill]], _extra=_extra
endfor
    oplot, [xloc[0], xloc[1]], [h[0], h[0]], _extra=_extra
    oplot, [xloc[nh-1], xloc[nh-1]+binss], [h[nh-1], h[nh-1]], _extra=_extra

xhist=locs
yhist=h
end
